package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.db.entity.Employee;
import com.xcity.db.entity.Player;
import com.xcity.game.battle.pve.PVEBattle;
import com.xcity.game.battle.pve.PVEStage;
import com.xcity.game.battle.pve.template.StageTemplate;
import com.xcity.game.common.ItemResponse;
import com.xcity.game.item.ItemInfo;

import naga.x.game.time.TimeUpdater;
import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@Deprecated
@PomeloMessage(type = Message.Type.RESPONSE)
public class PVEStageFightResponse extends Response {

	private int id;
	private short[] map;
	private int step; // 步数限制
	private int timeLimit; // 时间限制(秒)
	@JSONField(name = "element")
	private int[] blocks; // 该关卡可出现的色块
	@JSONField(name = "resist")
	private int[] invincibleBlocks; // 敌方免疫色块
//	@JSONField(name = "levelreq")
//	private List<BlockInfo> needClearBlocks; // 需消除的色块
	private /*List<BlockInfo>*/int attackreq; // 攻击条件
	@JSONField(name = "levelbgimg")
	private String background; // 战斗背景图
	
	private int attack; // 角色的攻击力
	private int hp, maxHp; // 角色的血量
	private String enemyName; // 敌方姓名
	private String enemyImg; // 敌方形象
	private int enemyHP, enemyMaxHp; // 敌方血量
	private int enemyAttack; // 敌方攻击力
	private int enemyAttackInterval; // 敌方攻击间隔
	private List<ItemResponse> items = Collections.emptyList(); // 携带的道具
	private long serverTime; // 服务器时间
	
	public static class BlockInfo implements Comparable<BlockInfo> {
		@JSONField(name = "type")
		private byte index;
		private int num;
		public byte getIndex() {
			return index;
		}
		public void setIndex(byte index) {
			this.index = index;
		}
		public int getNum() {
			return num;
		}
		public void setNum(int num) {
			this.num = num;
		}
		@Override
		public int compareTo(BlockInfo o) {
			return index - o.index;
		}
	}
	
	public PVEStageFightResponse(int serial, Player player, PVEStage stage, List<ItemInfo> items, List<Employee> employees, PVEBattle battle) {
		super(serial);
		this.id = stage.getId();
		StageTemplate template = stage.getTemplate();
		this.map = template.getMapData();
		this.step = template.getStep();
		this.timeLimit = template.getTimeLimit();
		this.blocks = template.getBlocksArr();
		this.invincibleBlocks = template.getInvincibleBlocksArr();
		this.attackreq = template.getAttackNeedBlockNum();
		this.background = template.getBgImage();
		this.attack = battle.getSource().getAttack();// PVEUtils.calcAttack(player, employees);
		this.hp = battle.getSource().getHp();//PVEUtils.getPlayerInitHP(player, employees);
		this.maxHp = battle.getSource().getMaxHp();
		this.enemyName = template.getEnemyName();
		this.enemyImg = template.getEnemyImage();
		this.enemyHP = battle.getTarget().getHp();//PVEUtils.getEnemyInitHP(player, employees, stage);
		this.enemyMaxHp = battle.getTarget().getMaxHp();
		this.enemyAttack = battle.getTarget().getAttack();//template.getEnemyAttack();
		this.enemyAttackInterval = template.getEnemyAttackCD();
		if (items != null && items.size() > 0) {
			this.items = new ArrayList<ItemResponse>(items.size());
			for (int i = 0; i < items.size(); i++) {
				this.items.add(new ItemResponse(items.get(i)));
			}
		}
		this.serverTime = TimeUpdater.getInstance().now();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public short[] getMap() {
		return map;
	}

	public void setMap(short[] map) {
		this.map = map;
	}

	public int getStep() {
		return step;
	}

	public void setStep(int step) {
		this.step = step;
	}

	public int getTimeLimit() {
		return timeLimit;
	}

	public void setTimeLimit(int timeLimit) {
		this.timeLimit = timeLimit;
	}

	public int[] getBlocks() {
		return blocks;
	}

	public void setBlocks(int[] blocks) {
		this.blocks = blocks;
	}

	public int[] getInvincibleBlocks() {
		return invincibleBlocks;
	}

	public void setInvincibleBlocks(int[] invincibleBlocks) {
		this.invincibleBlocks = invincibleBlocks;
	}

//	public List<BlockInfo> getNeedClearBlocks() {
//		return needClearBlocks;
//	}
//
//	public void setNeedClearBlocks(List<BlockInfo> needClearBlocks) {
//		this.needClearBlocks = needClearBlocks;
//	}

	public /*List<BlockInfo>*/int getAttackreq() {
		return attackreq;
	}

	public void setAttackreq(/*List<BlockInfo>*/int attackreq) {
		this.attackreq = attackreq;
	}

	public String getBackground() {
		return background;
	}

	public void setBackground(String background) {
		this.background = background;
	}

	public int getAttack() {
		return attack;
	}

	public void setAttack(int attack) {
		this.attack = attack;
	}

	public int getHp() {
		return hp;
	}

	public void setHp(int hp) {
		this.hp = hp;
	}

	public String getEnemyName() {
		return enemyName;
	}

	public void setEnemyName(String enemyName) {
		this.enemyName = enemyName;
	}

	public String getEnemyImg() {
		return enemyImg;
	}

	public void setEnemyImg(String enemyImg) {
		this.enemyImg = enemyImg;
	}

	public int getEnemyHP() {
		return enemyHP;
	}

	public void setEnemyHP(int enemyHP) {
		this.enemyHP = enemyHP;
	}

	public int getEnemyAttack() {
		return enemyAttack;
	}

	public void setEnemyAttack(int enemyAttack) {
		this.enemyAttack = enemyAttack;
	}

	public int getEnemyAttackInterval() {
		return enemyAttackInterval;
	}

	public void setEnemyAttackInterval(int enemyAttackInterval) {
		this.enemyAttackInterval = enemyAttackInterval;
	}

	public long getServerTime() {
		return serverTime;
	}

	public void setServerTime(long serverTime) {
		this.serverTime = serverTime;
	}

	public List<ItemResponse> getItems() {
		return items;
	}

	public void setItems(List<ItemResponse> items) {
		this.items = items;
	}

	public int getMaxHp() {
		return maxHp;
	}

	public void setMaxHp(int maxHp) {
		this.maxHp = maxHp;
	}

	public int getEnemyMaxHp() {
		return enemyMaxHp;
	}

	public void setEnemyMaxHp(int enemyMaxHp) {
		this.enemyMaxHp = enemyMaxHp;
	}

}
